package com.xinyun.traceability.controller;

import com.xinyun.traceability.enity.po.SysUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class IndexController {

    @GetMapping("/")
    public String main() {
        return "index";
    }

    /**
     * 主页
     */
    @GetMapping("/main")
    public String index(HttpSession session) {
        SysUser sysUser = (SysUser) session.getAttribute("sysUser");
        if (sysUser == null) {
            return "redirect:login";
        }
        return "main";
    }

    /**
     * 错误页
     */
    @RequestMapping("/error/{code}")
    public String error(@PathVariable("code") String code) {
        if ("403".equals(code)) {
            return "error/403";
        } else if ("500".equals(code)) {
            return "error/500";
        }
        return "error/404";
    }

    @GetMapping("/dashboard")
    public String dashboard() {
        return "dashboard";
    }
}
